<?php

use Biz\service\springHomeDecActivity\WishService;

class AllWishAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;
    const VALIDATOR_TOAST_DEBUG = true;
    const PAGE_SIZE = 20;

    //参数校验-规则
    public const VALIDATOR_RULES = [
        'page' => 'require|integer',
    ];

    //参数校验-自定义消息
    public const VALIDATOR_MSG = [
        'page.require' => '分页参数错误',
    ];

    public function main()
    {
        $page = $this->params['page'] ?? 1;
        $per_page = $this->params['per_page'] ?? self::PAGE_SIZE;
        $data = [
            'is_over' => 1,
            'list' => [],
        ];
        $data['total'] = WishService::AllWishCount();
        $result = WishService::AllUserWish($page, $per_page);
        if ($result && is_array($result)) {
            $data['list'] = $result;
            $data['is_over'] = count($result) < self::PAGE_SIZE ? 1 : 0;
        }
        $this->setSuccess($data);
    }
}